
#ifndef __LOCK_H__
#define __LOCK_H__

#include <windows.h>
#include <map>


class Storage
{
	typedef void *									key_type ;
	typedef	CRITICAL_SECTION *						value_type ;
	typedef std::map < key_type, value_type >		storage_type ; 
	typedef std::pair < storage_type, bool >		result_type ;

	CRITICAL_SECTION				critsec_ ;
	storage_type					storage_ ;

	void * insert ( key_type key ) ;
	void * erase ( key_type key ) ;
};


void * Storage::insert ( void * key )
{
	ScopedLock lock ( this->critsec_ ) ;


	storage_type::iterator itr = this->storage_.find ( key ) ;
	if ( itr == this->storage_.end () )
	{
		CRITICAL_SECTION * locker = new CRITICAL_SECTION() ;
		result_type	result = this->storage_.insert ( std::make_pair (key, locker) ) ;
		if ( result.second == false )
		{
			return NULL ;
		}
	}

	result_type	result = this->storage_.insert ( std::make_pair (key, locker) ) ;
	if ( result.second )
	{

	}

	return locker ;
}


result_type Storage::erase ( void * key )
{
	ScopedLock lock ( this->critsec_ ) ;

}


class Lock
{

public:
	Lock ( void * address ) ;
	~Lock ( void ) ;

public:
	void acquire ( void ) ;
	void release ( void ) ;

private:
	void *					address_ ;

};


Lock::Lock ( void * address )
:	address_(address)
{

}

Lock::~Lock ( void )
{

}

void Lock::acquire ( void * address )
{
	ScopedLock	lock ( this->critsec_ ) ;

	std::pair < std::map < void *, void * >, bool > result ;
	result = this->locked_.insert ( address, resource ) ;
	if ( result.second == false )	// already locked
	{
		delete resource ;
	}
	
	EnterCriticalSection ( result.first->second ) ;

	this->critsec_.LockCount
}

void Lock::release ( void * address )
{
	LeaveCriticalSection ( this->critsec_ ) ;
}


#endif	// #ifndef __LOCK_H__